<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>借书审核</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
</head>
<body style=" background-image: url('/images/book3.jpg');background-size: 100%;background-repeat: no-repeat; background-attachment: fixed; ">
<div class="layui-container" style="width: 960px;height: 600px;margin-top: 0px;padding-top: 60px;">
    <table class="layui-hide" id="test" lay-filter="test"></table>
    <script th:src="@{/layui/layui.js}" charset="utf-8"></script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="agree">同意</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="disagree">拒绝</a>
    </script>
    <script>
        layui.use('table', function(){
            var table = layui.table;

            table.render({
                elem: '#test'
                ,url:'/borrow/findAllByState'
                ,title: '读者借阅信息'
                ,cols: [
                    [
                        {field:'id', width:80, title: '编号', sort: true}
                        , {
                        field: 'bookname', width: 180, title: '图书', templet: function (data) {
                            return data.book.name
                        }
                    }
                        , {
                        field: 'name', width: 100, title: '读者', templet: function (data) {
                            return data.reader.name
                        }
                    }
                        ,{field:'borrowTime', width:180, title: '借书时间'}
                        ,{field:'returnTime',width:180,  title: '还书时间'}
                        ,{field:'state', width:160, title: '借书状态',templet:function(data){
                            var result = "";
                            switch (data.state) {
                                case 0:
                                    result = "未审核";
                                    break;
                                case 1:
                                    result = "审核通过";
                                    break;
                                case 2:
                                    result = "审核未通过";
                                    break;
                                case 3:
                                    result = "已归还";
                                    break;
                            }
                            return result
                        }
                    }
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:120}
                    ]
                ]
                ,page: true
            });


            //监听行工具事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                var bookId=data.book.id;
                if(obj.event === 'agree'){
                    layer.confirm('确定通过？', function(index){

                        window.location.href="/borrow/agreeBorrowed/"+data.id;
                        layer.close(index);
                    });
                } else if(obj.event === 'disagree'){
                    layer.confirm('确定拒绝？', function(index){
                        window.location.href="/borrow/disagreeBorrowed/"+data.id+"/"+bookId;
                        layer.close(index);
                    });
                }
            });

        });
    </script>

</div>
<script>
    //二级菜单联动
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
</body>
</html>